﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace UniFramework.Skill
{
    public partial class Skill
    {
        private void OnLogicFrameUpdateAnimation()
        {
            List<SkillAnimationConfigNode> dataList = skillConfig.skillAnimationList;
            if (dataList == null || dataList.Count == 0) return;

            bool HasStateLocal(Animator animator, string name)
            {
                int hash = Animator.StringToHash(name);
                return animator.HasState(0, hash);
            }

            foreach (var data in dataList)
            {
                Animator animator = this.releaser.GetComponent<Animator>();
                if (data.triggerFrame == _curLogicFrame)
                {
                    if (HasStateLocal(animator, data.name))
                    {
                        animator.Play(data.name);
                    }
                }

                if (data.endFrame == _curLogicFrame)
                {
                    if (HasStateLocal(animator, data.idleAnimationName))
                    {
                        animator.Play(data.idleAnimationName);
                    }
                }
            }
        }
    }
}